<template>
	<view class="scrool-page">
		<!-- <view>
			<uni-data-select  v-model="value" :localdata="range" ></uni-data-select>			
		</view> -->
		<view class="list-cont">
			<scroll-view class="scrool-more" style="height: 100%" scroll-y="true" scroll-with-animation="true">
				<view v-for="(item,index) in productList" :key="item.id">
					<uni-card :title="'序号:'+(index+1)" v-if="item.boxCode == null || item.boxCode == '' ">
						<text class="uni-body">物料编码：{{ item.itemCode }}</text><br>
						<text class="uni-body">数量：{{ item.qty }}</text><br>
						<text class="uni-body">库位：{{ item.storageAreaCode }}</text><br>
						<text class="uni-body">批次：{{ item.lotinfo }}</text><br>
						<text class="uni-body">箱码：{{ item.boxCode }}</text><br>
					</uni-card>

					<uni-card :title="'序号:'+(index+1)" v-else style='background-color: darkgrey;'>
						<text class="uni-body">物料编码：{{ item.itemCode }}</text><br>
						<text class="uni-body">数量：{{ item.qty }}</text><br>
						<text class="uni-body">库位：{{ item.storageAreaCode }}</text><br>
						<text class="uni-body">批次：{{ item.lotinfo }}</text><br>
						<text class="uni-body">箱码：{{ item.boxCode }}</text><br>
					</uni-card>
				</view>
			</scroll-view>
		</view>

		<view class="footer">
			<button type="default" size='mini' @click="reduceData" style="width:48%; margin-left:1%;"
				v-if="!userflag">减码</button>
			<button type="default" size='mini' @click="reduceData" style="width:48%; margin-left:1%;" v-else>加箱</button>
			<button type="default" size='mini' @click="submit" style="width:49%; margin-left:1%;">完成</button>
		</view>

		<uni-popup ref="alertDialog" type="dialog" :is-mask-click="false">
			<uni-popup-dialog type="success" cancelText="关闭" confirmText="确定" title="提示" :before-close="true"
				:content="content" @confirm="dialogConfirm" @close="dialogClose">
			</uni-popup-dialog>
		</uni-popup>

		<uni-popup ref="reduceDialog" type="dialog" :is-mask-click="false">
			<uni-popup-dialog type="success" cancelText="关闭" confirmText="确定" title="提示" :before-close="true"
				:content="reduceContent" @confirm="reduceConfirm" @close="reduceClose">
			</uni-popup-dialog>
		</uni-popup>

		<uni-popup ref="messageDialog" type="dialog" :is-mask-click="false">
			<uni-popup-dialog type="success" cancelText="关闭" confirmText="确定" title="提示" :before-close="true"
				:content="messageeContent" @confirm="messageConfirm" @close="messageClose">
			</uni-popup-dialog>
		</uni-popup>

		<uni-popup ref="dataDialog" type="dialog" :is-mask-click="false">
			<uni-popup-dialog type="success" cancelText="关闭" confirmText="确定" title="提示" :before-close="true"
				:content="dataContent" @confirm="dataConfirm" @close="dataClose">
			</uni-popup-dialog>
		</uni-popup>
		
		<uni-popup ref="commonDialog" type="dialog" :is-mask-click="false">
			<uni-popup-dialog type="success" cancelText="关闭" confirmText="确定" title="提示" :before-close="true"
				:content="commonContent" @confirm="commonConfirm" @close="commonClose">
			</uni-popup-dialog>
		</uni-popup>
		
		
		<uni-popup ref="checkDialog" type="dialog" :is-mask-click="false">
			<uni-popup-dialog type="success" cancelText="重新扫描" confirmText="确定" title="提示" :before-close="true"
				:content="checkContent" @confirm="checkConfirm" @close="checkClose">
			</uni-popup-dialog>
		</uni-popup>
	</view>

</template>

<script>
	import Vue from 'vue'
	import {
		getToken
	} from '@/utils/auth'
	import common from '../../pages/common/common.js'
	const printer = uni.requireNativePlugin('LcPrinter');
	const modal = uni.requireNativePlugin('modal');
	var globalEvent = uni.requireNativePlugin('globalEvent');
	var main, receiver, filter;
	var ScanDeviceClass = plus.android.importClass("android.device.ScanDevice");
	var scanDevice;
	export default {
		data() {
			return {
				productList: [],
				list: [],
				content: '',
				code: '',
				codeEqualQty: '',
				boxCode: '',
				allCode: "",
				count: 0,
				userflag: false,
				codeStr: '',
				popFlag: false,
				reduceContent: '',
				reduceCode: '',
				reduceNumkber: '',
				reducePatch: '',
				reduceCount: 0,
				type: '', //类别
				barcodeIdList: [],
				dataContent: '检测到有缓存数据是否加载？',
				messageeContent: '确认删除数据吗?',
				sumbitFlag: false,
				baseUrl: getApp().globalData.config.baseUrl,
				userName: this.$store.state.user.name,
				orgId: getApp().globalData.config.orgId,
				id: '',
				pkOrder: '',
				title: '',
				areaCode: '',
				value: 'WmMiscRcvTrans',
				range: [{
						value: 'WmMiscRcvTrans',
						text: "标准杂收"
					},
					{
						value: 'WmMiscRcvTransExchange',
						text: "以货换货"
					},
					{
						value: 'WmMiscRcvTransUrgent',
						text: "紧急出货"
					},
				],
				status: '',
				index: '',
				
				commonContent: '',
				checkContent: '扫描数量与系统内该品番箱容数不一致是否继续',
				qtyStatus: 0, //默认为0   扫描组长的二维码后 1
				checkCode: '',
				
				isLastCase: '',
				boxPile: "",
				flag: 0
			}
		},

		watch: {
			popFlag: {
				handler(newValue, oldValue) {
					if (newValue) {
						this.$refs.alertDialog.open();
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode + '\n';
					}
				}
			}

		},

		onHide: function() {
			this.unregisterScan();
		},

		destroyed: function() {
			this.unregisterScan();
		},

		onLoad: function(option) {
			this.orgId = uni.getStorageSync('orgId');
			this.id = option.id;
			this.pkOrder = option.pkOrder;
			this.title = option.title;
			this.status = option.status;
			this.index = option.index;
			uni.setNavigationBarTitle({
				title: this.title
			});
			// 添加打印状态监听
			globalEvent.addEventListener('onPrintCallback', function(e) {
				// uni.showToast({
				// 	title: 'state: ' + JSON.stringify(e),
				// 	duration: 2000
				// });
				if (e.key == 0) {
					// uni.showToast({
					// 	title: '打印成功',
					// 	duration: 2000
					// });
				} else if (e.key == 3) {
					uni.showToast({
						title: '缺纸',
						duration: 2000
					});
				}
			});
			//打印机版本获取回调
			globalEvent.addEventListener('onVersion', function(e) {
				// uni.showToast({
				// 	title: 'version: ' + JSON.stringify(e),
				// 	duration: 2000
				// });
			});

			globalEvent.addEventListener('getsupportprint', function(e) {
				console.log('key: ' + JSON.stringify(e));
				// uni.showToast({
				// 	title: 'key: ' + JSON.stringify(e),
				// 	duration: 2000
				// });
			});
		},

		onShow() {
			scanDevice = new ScanDeviceClass();
			scanDevice.openScan(); // 打开扫描
			scanDevice.setOutScanMode(0); // 扫描模式				
			this.initScan();
			this.registerScan();
		},

		mounted() {
			this.orgId = uni.getStorageSync('orgId');
			const value = uni.getStorageSync('product_recpt_misc_rcv' + this.id);
			if (value.length > 0) {
				this.list = value;
				this.$refs.dataDialog.open();
			} else {
				this.queryBatch(this.pkOrder);
				this.list = [];
				this.productList = [];
			}
		},

		onBackPress(options) {
			if (options.from === 'navigateBack') {
				return false;
			}
			//this.unregisterScan();
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let nowPage = pages[pages.length - 1]; //当前页页面实例
			let prevPage = pages[pages.length - 2]; //上一页页面实例
			if (!this.sumbitFlag) {
				try {
					uni.setStorageSync('product_recpt_misc_rcv' + this.id, this.productList);
				} catch (e) {
					console.log(e.message);
				}
			}
			prevPage.$vm.chooseTab(this.index);
			uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
				delta: 1
			});
			return true;
		},

		methods: {
			initScan(popFlag) {
				let _this = this;
				main = plus.android.runtimeMainActivity(); //获取activity  
				var IntentFilter = plus.android.importClass('android.content.IntentFilter');
				filter = new IntentFilter();
				filter.addAction("scan.rcv.message"); // 换你的广播动作  
				receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
					onReceive: function(context, intent) {
						plus.android.importClass(intent);
						let code = intent.getByteArrayExtra('barocode');
						let codeStr = common.utf8ByteToUnicodeStr(code);
						scanDevice.stopScan(); // 停止扫描
						var result = common.scanCode(codeStr);
						if (result[0] == 'K') {
							_this.resYes(result[1]);
						} else {
							_this.buttonScan(codeStr);
							_this.viewScan(codeStr);
						}
					}
				});
			},

			queryBatch(id) {
				uni.request({
					url: this.baseUrl + '/system/MiscRcvTrans/getWmMiscRcvTransBoxList',
					data: {
						pid: id,
					},
					method: 'GET',
					header: {
						'authorization': getToken()
					},
					dataType: 'json',
					success: (res) => {
						console.log(res.data.rows)
						var code = res.data.code;
						if (res.data.rows[0].attr1) {
							this.type = res.data.rows[0].attr1
						} else {
							this.type = undefined
						}

						//console.log(this.type)
						if (code == '200') {
							this.productList = res.data.rows;
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 3000
							});
						}
					}
				})
			},

			//扫描减码
			reduceData() {
				if (this.status == '2') {
					uni.showToast({
						title: '任务已挂起，请先恢复',
						icon: 'none',
						duration: 3000
					});
					return;
				}

				if (this.status == '3') {
					uni.showToast({
						title: '任务已完成，不能修改',
						icon: 'none',
						duration: 3000
					});
					return;
				}
				if (this.userflag) {
					this.userflag = false;
				} else {
					this.userflag = true;
				}
			},

			//如果是机器上面的扫描按钮，是增加数据
			buttonScan(codeStr) {
				if (this.status == '2') {
					uni.showToast({
						title: '任务已挂起，请先恢复',
						icon: 'none',
						duration: 3000
					});
					return;
				}

				if (this.status == '3') {
					uni.showToast({
						title: '任务已完成，不能修改',
						icon: 'none',
						duration: 3000
					});
					return;
				}
				var that = this;
				if (that.userflag) {
					return;
				}
				if (codeStr == null || codeStr == '') {
					uni.showToast({
						title: '请正确扫描编码',
						icon: 'none',
						duration: 3000
					});
					return;
				}
				if (that.areaCode == null || that.areaCode == '') {
					uni.showToast({
						title: '请先扫描库位',
						icon: 'none',
						duration: 3000
					});
					return;
				}

				if (!that.popFlag) {
					that.popFlag = true;
				}
				that.$refs.alertDialog.open();
				var result = common.scanCode(codeStr);



				console.log(this.orgId)
				if (this.orgId == '1002209130004396') {
					console.log(result)
					if (result[0] == "C") {
						this.allCode = codeStr;
						for (var j = 0; j < this.productList.length; j++) {
							if (this.productList[j].boxCode == result[1]) {
								this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
									.boxCode + '\n';
								this.commonContent = result[1] + '此数据已存在';
								this.$refs.commonDialog.open();
								return;
							}
						}
						this.boxCode = result[1];
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.checkCode = ''
						this.qtyStatus = 0
					} else if (result[0] == "P") {
						// setTimeout(function() {
						this.code = result[1];
						// }, 100);
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.checkCode = ''
						this.qtyStatus = 0
					} else if (result[0] == "Q") {
						this.codeEqualQty = result[1];
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.checkCode = ''
						this.qtyStatus = 0
					} else if (result[0] == "Z") {
						if (result[1] == '03350') {
							this.checkCode = result[1];
						} else {
							this.commonContent = '请扫描正确的组长号';
							this.$refs.commonDialog.open();

						}

						console.log(this.checkCode)
						// this.checkContent  = '组长工号：'+this.code
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n' + '组长工号：' + this.checkCode;
						if (this.checkCode != '') {
							this.qtyStatus = 1
						} else {
							this.qtyStatus = 0
						}
					} else if (result[0] == "SZYW") {

						this.commonContent = '请扫描正确的组长号';
						this.$refs.commonDialog.open();
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n' + '组长工号：' + this.checkCode;

						this.qtyStatus = 0
					} else {
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.commonContent = '请正确扫描条码';
						this.$refs.commonDialog.open();
						return;
					}
				} else {
					console.log(result)
					if (result[0] == "C") {
						this.allCode = codeStr;
						for (var j = 0; j < this.productList.length; j++) {
							if (this.productList[j].boxCode == result[1]) {
								this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
									.boxCode + '\n';
								this.commonContent = result[1] + '此数据已存在';
								this.$refs.commonDialog.open();
								return;
							}
						}
						this.boxCode = result[1];
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.checkCode = ''
						this.qtyStatus = 0
					} else if (result[0] == "P") {

						this.code = result[1];

						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.checkCode = ''
						this.qtyStatus = 0
					} else if (result[0] == "Q") {
						this.codeEqualQty = result[1];
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.checkCode = ''
						this.qtyStatus = 0
					} else if (result[0] == "Z") {


						this.commonContent = '请扫描正确的组长号';
						this.$refs.commonDialog.open();
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n' + '组长工号：' + this.checkCode;

						this.qtyStatus = 0
					} else if (result[0] == "SZYW") {
						if (result[1] == '00135') {
							this.checkCode = result[1];
						} else {
							this.commonContent = '请扫描正确的组长号';
							this.$refs.commonDialog.open();

						}
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n' + '组长工号：' + this.checkCode;

						if (this.checkCode != '') {
							this.qtyStatus = 1
						} else {
							this.qtyStatus = 0
						}


					} else {
						this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this
							.boxCode +
							'\n';
						this.commonContent = '请正确扫描条码';
						this.$refs.commonDialog.open();
						return;
					}
				}


				// if (result[0] == "P") {
				// 	var flag = false;
				// 	for (var i = 0; i < that.productList.length; i++) {
				// 		if (that.productList[i].itemCode == result[1]) {
				// 			flag = true;
				// 			break;
				// 		}
				// 	}
				// 	if (flag) {
				// 		that.code = result[1];
				// 		that.count = parseInt(that.count) + 1;
				// 		that.content = '物料编码：' + that.code + "\n" + "数量：" + that.codeEqualQty + "\n" + '箱码：' + that
				// 			.boxCode + '\n';
				// 	} else {
				// 		uni.showToast({
				// 			title: '此物料编码不存在',
				// 			icon: 'none',
				// 			duration: 4000
				// 		});
				// 		return;
				// 	}
				// } else if (result[0] == "Q") {
				// 	that.count = parseInt(that.count) + 1;
				// 	//that.content = '物料编码：' +that.code+"\n"+"数量："+that.codeEqualQty+"\n"+'箱码：'+that.boxCode+'\n';
				// 	var flag = false;
				// 	for (var i = 0; i < that.productList.length; i++) {
				// 		if (that.productList[i].qty == result[1]) {
				// 			flag = true;
				// 			break;
				// 		}
				// 	}
				// 	if (flag) {
				// 		that.codeEqualQty = result[1];
				// 		that.count = parseInt(that.count) + 1;
				// 		that.content = '物料编码：' + that.code + "\n" + "数量：" + that.codeEqualQty + "\n" + '箱码：' + that
				// 			.boxCode + '\n';
				// 	} else {
				// 		uni.showToast({
				// 			title: "箱容数与该列表中箱容数不匹配",
				// 			icon: 'none',
				// 			duration: 5000
				// 		});
				// 		return;
				// 	}
				// } else if (result[0] == "C") {
				// 	var flag = false;
				// 	for (var i = 0; i < that.productList.length; i++) {
				// 		if (that.productList[i].boxCode == result[1]) {
				// 			flag = true;
				// 			break;
				// 		}
				// 	}
				// 	if (flag) {
				// 		uni.showToast({
				// 			title: '此数据已存在',
				// 			icon: 'none',
				// 			duration: 4000
				// 		});
				// 		return;
				// 	} else {
				// 		var flag = false;
				// 		for (var i = 0; i < that.productList.length; i++) {
				// 			var data = that.productList[i];
				// 			if (data.lotinfo == result[1].substring(0, 9) && (data.boxCode == null || data.boxCode ==
				// 					'')) {
				// 				flag = true;
				// 			}
				// 		}
				// 		if (flag) {
				// 			that.allCode = codeStr;
				// 			that.boxCode = result[1];
				// 			that.content = '物料编码：' + that.code + "\n" + "数量：" + that.codeEqualQty + "\n" + '箱码：' + that
				// 				.boxCode + '\n';
				// 		} else {
				// 			uni.showToast({
				// 				title: '此批次的数据不存在或者已经扫描完成',
				// 				icon: 'none',
				// 				duration: 5000
				// 			});
				// 			return;
				// 		}
				// 	}
				// } else {
				// 	uni.showToast({
				// 		title: '请正确扫描编码',
				// 		icon: 'none',
				// 		duration: 5000
				// 	});
				// 	return;
				// }
			},

			resYes(warehouseLocation) {
				uni.request({
					url: this.baseUrl + '/system/area/ResYes',
					data: {
						areaCode: warehouseLocation,
						userName: this.userName,
						orgId: this.orgId,
					},
					method: 'POST',
					header: {
						'authorization': getToken()
					},
					dataType: 'json',
					success: (res) => {
						//隐藏加载框
						uni.hideLoading();
						if (res.data) {
							console.log(res);
							this.areaCode = warehouseLocation;
							uni.setNavigationBarTitle({
								title: this.title.split('-')[1] + '(' + this.areaCode + ")"
							});
						} else {
							uni.showToast({
								title: warehouseLocation + '不存在或者不可用',
								icon: 'none',
								duration: 3000
							});
							return;
						}

					},
				})
			},

			queryByBoxCode(codeStr) {
				var that = this;
				uni.request({
					url: that.baseUrl + '/system/barcode/box',
					data: {
						userName: that.userName,
						boxCode: codeStr,
						orgId: that.orgId,
					},
					method: 'POST',
					header: {
						'authorization': getToken()
					},
					dataType: 'json',
					success: (res) => {
						if (res.data.code == '200' || res.data.code == 200) {
							var result = res.data.data;
							var flag = false;
							for (var i = 0; i < that.productList.length; i++) {
								var data = that.productList[i];
								if (data.lotinfo == result.batchNumber && (data.boxCode == null || data
										.boxCode == '')) {
									flag = true;
								}
							}
							if (flag) {
								that.boxCode = codeStr;
								that.content = '物料编码：' + that.code + "\n" + "数量：" + that.codeEqualQty + "\n" +
									'箱码：' + that.boxCode + '\n';
							} else {
								uni.showToast({
									title: '此批次的数据不存在或者已经扫描完成',
									icon: 'none',
									duration: 5000
								});
								return;
							}
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
							return;
						}

					},
				})
			},

			//如果是页面上的减码扫描，那就是删除数据
			viewScan(codeStr) {
				if (!this.userflag) {
					return;
				}
				var result = common.scanCode(codeStr);
				if (result[0] == "C") {
					var flag = false;
					for (var i = 0; i < this.productList.length; i++) {
						var data = this.productList[i];
						if (data.boxCode == result[1]) {
							data.boxCode = '';
							data.storageAreaCode = '';
							flag = true;
							break;
						}
					}
					if (!flag) {
						uni.showToast({
							title: '未找到该' + result[1] + '箱号',
							icon: 'none',
							duration: 5000
						});
						return;
					}
				} else {
					uni.showToast({
						title: '请正确扫描编码',
						icon: 'none',
						duration: 5000
					});
					return;
				}

			},

			//组托
			submit() {
				if (this.status == '2') {
					uni.showToast({
						title: '任务已挂起，请先恢复',
						icon: 'none',
						duration: 3000
					});
					return;
				}

				if (this.status == '3') {
					uni.showToast({
						title: '任务已完成，不能修改',
						icon: 'none',
						duration: 3000
					});
					return;
				}
				//显示加载框
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				var that = this;
				var flag = false;
				for (var i = 0; i < that.productList.length; i++) {
					var data = that.productList[i];
					if (data.boxCode == null || data.boxCode == '') {
						flag = true;
						break;
					}
				}
				if (flag) {
					//隐藏加载框
					uni.hideLoading();
					uni.showModal({
						title: '提示',
						content: '此杂收单还未完成是否临时保存?',
						success: function(res) {
							if (res.confirm) {
								uni.setStorageSync('product_recpt_misc_rcv' + that.id, that.productList);
								//that.unregisterScan();
								let pages = getCurrentPages(); //获取所有页面栈实例列表
								let nowPage = pages[pages.length - 1]; //当前页页面实例
								let prevPage = pages[pages.length - 2]; //上一页页面实例
								prevPage.$vm.chooseTab(that.index);
								setTimeout(function() {
									uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
										delta: 1
									});
								}, 1000);
							} else {
								return;
							}
						}
					})
				} else {
					try {
						uni.removeStorageSync('product_recpt_misc_rcv' + that.id);
					} catch (e) {
						console.log(e.message);
					}
					let token = getToken();
					var wmMiscRcvTransBox = {
						userName: that.userName,
						productList: that.productList,
						orgId: that.orgId
					};
					var wmsBacklog = {
						id: that.id,
						executor: that.userName,
						orgId: that.orgId,
						startTime: '',
						endTime: new Date().toISOString().slice(0, 10),
						status: '3'
					};
					uni.request({
						url: that.baseUrl + '/system/MiscRcvTrans/newbatchUpdateWmMiscRcvTransBox',
						data: {
							wmMiscRcvTransBox: JSON.stringify(wmMiscRcvTransBox),
							wmsBacklog: wmsBacklog,
						},
						method: 'POST',
						header: {
							'authorization': token
						},
						dataType: 'json',
						success: (res) => {
							that.sumbitFlag = true;
							var code = res.data.code;
							if (code == '200') {
								//that.updateTask();
								uni.showToast({
									title: '操作成功并且代办任务已完成',
									icon: 'none',
									duration: 3000
								});
								setTimeout(function() {
									let pages = getCurrentPages(); //获取所有页面栈实例列表
									let nowPage = pages[pages.length - 1]; //当前页页面实例
									let prevPage = pages[pages.length - 2];
									prevPage.$vm.chooseTab(that.index);
									uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
										delta: 1
									});
								}, 1000);
							} else {
								//隐藏加载框
								uni.hideLoading();
								uni.showToast({
									title: res.data.msg,
									icon: 'none',
									duration: 3000
								});
							}
						}
					})
				}
			},

			//更新代办任务状态为完成
			updateTask() {
				var that = this;
				//显示加载框
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				uni.request({
					url: that.baseUrl + '/system/wmsbacklog/update',
					data: {
						id: that.id,
						executor: that.userName,
						orgId: that.orgId,
						startTime: '',
						endTime: new Date().toISOString().slice(0, 10),
						status: '3' //完成状态
					},
					method: 'POST',
					header: {
						'authorization': getToken()
					},
					dataType: 'json',
					success: (res) => {
						//隐藏加载框
						uni.hideLoading();
						//that.unregisterScan();
						if (res.data.code == '200' || res.data.code == 200) {
							uni.showToast({
								title: '操作成功并且代办任务已完成',
								icon: 'none',
								duration: 3000
							});
							setTimeout(function() {
								let pages = getCurrentPages(); //获取所有页面栈实例列表
								let nowPage = pages[pages.length - 1]; //当前页页面实例
								let prevPage = pages[pages.length - 2];
								prevPage.$vm.chooseTab(that.index);
								uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
									delta: 1
								});
							}, 1000);
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 3000
							});
							return;
						}

					},
				})
			},



			registerScan() {
				main.registerReceiver(receiver, filter);
			},

			unregisterScan() {
				main.unregisterReceiver(receiver);
			},

			dialogToggle(type) {
				//this.$refs.alertDialog.open();
			},

			dialogConfirm() {
				//显示加载框
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				//如果三个码都扫描完成
				var that = this;
				if (that.code == null || that.code == '') {
					uni.showToast({
						title: '请扫描物料编码',
						icon: 'error',
						duration: 2000
					});
					return;
				} else if (that.codeEqualQty == null || that.codeEqualQty == '') {
					uni.showToast({
						title: '请扫描数量',
						icon: 'error',
						duration: 2000
					});
					return;
				} else if (that.boxCode == null || that.boxCode == '') {
					uni.showToast({
						title: '请扫描箱码',
						icon: 'error',
						duration: 2000
					});
					return;
				} else {
					// var flag = false;
					// for(var i=0;i<that.productList.length;i++){
					// 	var data = that.productList[i];
					// 	if(data.itemCode == that.code && data.qty==that.codeEqualQty && data.lotinfo == that.boxCode.substring(0,9) && (data.boxCode == null ||data.boxCode == '')){
					// 		flag = true;
					// 		break;
					// 	}
					// }
					// var flag = false;
					// for (var i = 0; i < that.productList.length; i++) {
					// 	var data = that.productList[i];
					// 	if (data.itemCode == that.code && (data.boxCode == null || data.boxCode == '')) {
					// 		flag = true;
					// 		break;
					// 	}
					// }
					// if (!flag) {
					// 	uni.showToast({
					// 		title: '物料编码为' + that.code + '的数据不存在或者已被扫描',
					// 		icon: 'none',
					// 		duration: 5000
					// 	});
					// 	return;
					// }
					// if(!flag){
					// 	uni.showToast({
					// 		title: '物料编码为'+that.code+'数量为'+that.codeEqualQty+'批次为'+that.boxCode.substring(0,9)+'的数据不存在或者已被扫描',
					// 		icon: 'none',
					// 		duration: 5000
					// 	});
					// 	return;
					// }
					let token = getToken();
					uni.request({
						url: that.baseUrl + '/system/barcode',
						data: {
							orgId: that.orgId,
							code: that.code,
							codeEqualQty: that.codeEqualQty,
							boxCode: that.boxCode,
							sourceBill: 'MD_ITEM_SINGLE', //单据类型是物料,
							type: that.type,
							userName: that.userName,
							qtyStatus: that.qtyStatus
						},
						method: 'POST',
						header: {
							'authorization': getToken()
						},
						dataType: 'json',
						success: (res) => {
							//隐藏加载框
							uni.hideLoading();
							if (res.data.code == '200') {
								//that.productList.push({itemCode:that.code,qty:that.codeEqualQty,storageAreaCode:that.areaCode,lotInfo:that.boxCode.split(0,9),boxCode:that.boxCode,flag:false});
								for (var i = 0; i < that.productList.length; i++) {
									var data = that.productList[i];
									//if(data.itemCode == that.code && data.qty == that.codeEqualQty && data.lotinfo == that.boxCode.substring(0,9)  && (data.boxCode == null || data.boxCode == '')){
									if (data.itemCode == that.code && (data.boxCode == null || data.boxCode ==
											'')) {
										data.qty = that.codeEqualQty;
										data.storageAreaCode = that.areaCode;
										//data.batchNumber = that.boxCode.substring()(0,9);
										data.boxCode = that.boxCode;
										data.lotinfo = that.boxCode.substring(0, 9);
										data.allCode = that.allCode;
										//data.code = that.itemCode;
										//data.codeEqualQty = that.codeEqualQty;
										break;
									}
								}
								that.code = '';
								that.codeEqualQty = '';
								that.boxCode = '';
								that.allCode = "";
								that.count = '0';
								that.popFlag = false;
								that.$refs.alertDialog.close();
							} else if (res.data.code == '201') {
								uni.showToast({
									title: res.data.msg,
									icon: 'none',
									duration: 2000
								});
							} else if (res.data.ccode == '96') {
								uni.showToast({
									title: res.data.msg,
									icon: 'none',
									duration: 3000
								});
							} else if (res.data.code == '601') {
								uni.hideLoading();
								that.$refs.checkDialog.open();
							} else if (res.data.code == '602') {
								uni.hideLoading();
								that.qtyStatus = 1
								that.$refs.checkDialog.open();
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none',
									duration: 4000
								});
								that.code = '';
								that.codeEqualQty = '';
								that.boxCode = '';
								that.allCode = "";
								that.count = '0';
								that.popFlag = false;
								//that.$refs.alertDialog.close();
							}

						}
					})
				}
			},

			dialogClose() {
				this.code = '';
				this.codeEqualQty = '';
				this.boxCode = '';
				this.allCode = "";
				this.count = '0';
				this.popFlag = false;
				this.$refs.alertDialog.close();
			},

			reduceConfirm() {
				var tempList = [];
				for (var i = 0; i < this.productList.length; i++) {
					if (this.productList[i].boxCode == this.reducePatch) {

					} else {
						tempList.push(this.productList[i]);
					}
				}
				this.productList = [];
				this.productList = tempList;
				this.$refs.reduceDialog.close();
				this.reduceCode = '';
				this.reduceNumkber = '';
				this.reducePatch = '';
				this.reduceCount = 0;
				this.userflag = false;

			},

			reduceClose() {
				this.reduceCode = '';
				this.reduceNumkber = '';
				this.reducePatch = '';
				this.reduceCount = 0;
				this.userflag = false;
				this.$refs.reduceDialog.close();
			},

			dataConfirm() {
				this.productList = this.list;
				try {
					uni.removeStorageSync('product_recpt_misc_rcv' + this.id);
				} catch (e) {
					console.log(e.message);
				}
				this.$refs.dataDialog.close();
			},

			dataClose() {
				this.list = [];
				try {
					uni.removeStorageSync('product_recpt_misc_rcv' + this.id);
				} catch (e) {
					console.log(e.message);
				}
				this.queryBatch(this.pkOrder);
				//this.productList = [];
				this.$refs.dataDialog.close();
			},

			messageConfirm() {
				scanDevice.stopScan(); // 停止扫描
				scanDevice.startScan();
				this.$refs.messageDialog.close();
			},

			messageClose() {
				this.userflag = false;
				this.$refs.messageDialog.close();
			},
			
			commonConfirm() {
				this.commonContent = "";
				this.$refs.commonDialog.close();
			},
			
			commonClose() {
				this.commonContent = "";
				this.$refs.commonDialog.close();
			},
			
			// 箱容数校验弹窗
			checkConfirm() {
				console.log('aaa')
				this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this.boxCode +
					'\n' + '组长工号：' + this.checkCode;
			
				this.isLastCase = 1 //是否尾箱，1是尾箱，0是非尾箱
				this.qtyStatus = 0
				this.$refs.checkDialog.close();
			},
			checkClose() {
				this.code = ''
				this.codeEqualQty = ''
				this.boxCode = ''
				this.qtyStatus = 0
				this.content = '物料编码：' + this.code + "\n" + "数量：" + this.codeEqualQty + "\n" + '箱码：' + this.boxCode +
					'\n';
			
				this.$refs.checkDialog.close();
			},
		}
	}
</script>

<style lang="scss">
	.main {
		background-color: #fff;
		height: 300upx;
		align-items: center;
		margin-top: 10upx;
	}

	.text-content {
		font-size: 48rpx;
		text-align: center;
	}

	.city {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		// width: 160rpx;
		margin-left: 4px;
		font-size: 26rpx;
	}

	.input-view {
		display: flex;
		flex-direction: row;
		flex: 1;
		//background-color: #f8f8f8;
		height: 30px;
		padding: 0 80px;
		flex-wrap: nowrap;
		margin: 7px 0;
		line-height: 30px;
		font-size: 26rpx;
	}

	page {
		width: 100%;
		height: 100%;
	}


	.scrool-page {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100%;
	}

	.header-cont {
		width: 100%;
		height: 110rpx;
		line-height: 100rpx;
		text-align: center;
		// background: red;
	}

	.list-cont {
		flex: 1;
		position: relative;

		.scrool-more {
			position: absolute;
			left: 0;
			right: 0;
			top: 0;
			bottom: 0;
		}

		.list {
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: #e0e0e0;

		}
	}


	.footer {
		color: #fff;
		line-height: 100rpx;
		flex: 0 0 100rpx;
		/* 不放大不缩小固定100rpx */
	}
</style>